package com.leokok.jts.learning.jts.core.algorithm;

import org.junit.Test;
import org.locationtech.jts.algorithm.ConvexHull;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 凸包计算
 * 运用Graham scan算法计算凸包
 */
public class ConvexHullTest {

    @Test
    public void convexHull() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("MULTIPOINT ((115.931 31.996), (115.932 31.996), (115.935 31.997), (115.937 31.997), (115.941 31.998), (115.944 31.998), (115.947 31.999), (115.935 31.994), (115.935 31.993), (115.9357 31.9906), (115.936 31.989), (115.9365 31.9938), (115.938 31.994), (115.941 31.994), (115.944 31.994), (115.944 31.994), (115.944 31.993), (115.943 31.991), (115.9416 31.9895), (115.938 31.989), (115.94 31.989), (115.935 31.986), (115.939 31.987), (115.932 31.984), (115.929 31.983), (115.935 31.982), (115.937 31.982), (115.94 31.985), (115.944 31.987), (115.946 31.991), (115.93 31.989), (115.931 31.992))");
        ConvexHull convexHull = new ConvexHull(geometry);
        Geometry convexHullGeo = convexHull.getConvexHull();
        System.out.println(convexHullGeo.toText());
    }
}
